package net.easyjava.base.service.impl;

import net.easyjava.base.bean.UserBean;
import net.easyjava.base.dao.UserDao;
import net.easyjava.base.service.UserService;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by wenxiaoning on 15/12/18.
 */
@Component
public class UserServiceImpl implements UserService {
    @Resource
    private UserDao userDao;
    /**
     * 保存用户
     *
     * @param userBean
     * @return
     */
    @Override
    public UserBean save(UserBean userBean) {
        return userDao.save(userBean)>0?find(userBean.getId()):null;
    }

    /**
     * 根据用户id查找用户
     *
     * @param id
     * @return
     */
    @Override
    public UserBean find(String id) {
        return userDao.find(id);
    }

    /**
     * 通过姓名密码查找用户
     *
     * @param name
     * @param password
     * @return
     */
    @Override
    public UserBean find(String name, String password) {
        Map<String,Object> params = new HashMap<String,Object>();
        params.put("userName",name);
        params.put("password",password);
        return userDao.findByParam(params);
    }
}
